package com.healthcarex.hip.saas.message.factory;


import com.healthcarex.hip.saas.message.core.MessageConstant;
import com.healthcarex.hip.saas.message.handler.DateValueHandler;
import com.healthcarex.hip.saas.message.handler.DefaultValueHandler;
import com.healthcarex.hip.saas.message.handler.IValueHandler;
import com.healthcarex.hip.saas.message.handler.StringValueHandler;
import org.apache.commons.lang3.StringUtils;

public class ValueHandlerFactory {

    public static IValueHandler getValueHandler(String type) {
        if (StringUtils.isNotBlank(type)) {
            type = type.trim();
            if (isDateOrTimeType(type)) {
                return new DateValueHandler();
            }
            if (MessageConstant.DATA_TYPE_STRING.equalsIgnoreCase(type)) {
                return new StringValueHandler();
            }
            return new DefaultValueHandler();
        }
        return null;
    }

    private static boolean isDateOrTimeType(String type) {
        if (MessageConstant.DATA_TYPE_DATE.equalsIgnoreCase(type)
                || MessageConstant.DATA_TYPE_TIME.equalsIgnoreCase(type)
                || MessageConstant.DATA_TYPE_TIMESTAMP.equalsIgnoreCase(type)) {
            return true;
        }

        return false;
    }

}
